package com.qianfeng.config;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileUploadBase;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@ControllerAdvice
public class MyExceptionHandlerAdvice {

    @ExceptionHandler(FileUploadBase.SizeLimitExceededException.class)
    public String exceptionUploadMaxResolver(FileUploadBase.SizeLimitExceededException exception) {

        log.debug("文件上传超过限制");

        return "upload_failed";
    }

    @ExceptionHandler(Exception.class)
    public String allException(Exception exception) {
        log.debug("");
        /*获取异常*/
        String msg = exception.getMessage();
        /*获取第二行的数据*/
        Pattern pattern = Pattern.compile("\\r\\n(.*)\\r\\n");
        Matcher msg1 = pattern.matcher(msg);
        while(msg1.find()){
            msg = msg1.group(1);
            break;
        }

        return "index";
    }
}
